import 'dart:io';

import 'package:flutter/material.dart';
import 'package:test1/View/MyRowText.dart';

class Flutter_Data_Dart_Simple_Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return Flutter_Data_Dart_Simple_State();
  }
}

class Flutter_Data_Dart_Simple_State
    extends State<Flutter_Data_Dart_Simple_Page> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("顺序执行"),
        ),
        body: ListView(
          children: <Widget>[
            MyRowText("调用同步模式函数Directory.createSync", () {
              var directory = new Directory("directory1");
              directory.createSync();
              debugPrint("directory1    ${directory.absolute.path}");
            }),
            MyRowText("将执行的之后的代码放到then函数中", () {
              var directory = new Directory("directory2");
              directory.create().then(
                      (dir) {
                    debugPrint("directory2    ${directory.absolute.path}");
                    debugPrint("directory2    ${dir.absolute.path}");
                  }
              );
            }),
            MyRowText("调用同步模式函数Directory.createSync", () async {
              var directory = new Directory("directory3");
              await directory.create();
              debugPrint("directory3    ${directory.absolute.path}");
            }),
          ],
        ),
      ),
    );
  }
}

/**
    等待函数执行完毕后，再执行之后的代码一般有以下3种方法：
    直接调用同步模式函数，如：Directory.createSync
    将执行的之后的代码放到then函数中
    使用关键字await，外层函数用async声明返回值为Future
 */
